<?php
class Photo extends CI_Model {

	function get_foto($id = NULL, $user_id = NULL, $limit=NULL, $offset=0, $private = NULL){
		$this->db->select('foto.*, alumni.nama as writer');
		$this->db->from('foto');
		$this->db->join('alumni','alumni.id_user=foto.id_user');
		if($id != NULL){
			$this->db->where('foto.id_foto', $id);
		}
		if($user_id != NULL){
			$this->db->where('foto.id_user', $user_id);
		}
		if($private != NULL){
			$this->db->where('foto.status', $private);
		}
		$this->db->order_by('foto.waktu_posting', 'DESC');
		if($limit != NULL){
			$this->db->limit($limit, $offset);
		}
		$query = $this->db->get();
		return $query->result_array();
	}
	
	function add($data){
		$this->db->insert('foto',$data);
		return $this->db->insert_id();
	}
	
	function edit($id, $data){
		$this->db->where('id_foto', $id);
		$this->db->update('foto',$data);
	}
	
	function delete($id){
		$this->db->delete('foto', array('id_foto' => $id)); 
	}
}
?>
